#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define ep emplace_back
#define pb push_back
#define PII pair<int,int>
#define rgt first
#define lft second
char buf[1 << 20],*p1,*p2;
#define gc() ((p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1 << 20,stdin),p1 == p2)) ? 0 : *p1++)
int read(){
    int x = 0,f = 1,ch = gc();
    while(!isdigit(ch)){
        if(ch == '-') f = -1;
        ch = gc();
    }
    while(isdigit(ch)){
        x = x * 10 + (ch ^ 48);
        ch = gc();
    }
    return x * f;
}
const int N = 100005;
int n,m,L,V;
int d[N],v[N],a[N],p[N];
vector<PII> vec;
void solve(){
    vec.clear();
    n = read(),m = read(),L = read(),V = read();
    rep(i,1,n){
        d[i] = read(),v[i] = read(),a[i] = read();
        if(a[i] == 0){
            if(v[i] > V){
                //cout << d[i] << " " << L << endl;
                vec.ep(L,d[i]);
            }
        }
        if(a[i] > 0){
            //int s = floor(S) + 1;
            int s = (V * V - v[i] * v[i]) / (2 * a[i]) + 1;
            if(d[i] + s <= L){
                if(s < 0) s = 0;
                //cout << s << " " << d[i] << " " << d[i] + s << " " << L << endl;
                vec.ep(L,d[i] + s);
            }
        }
        if(a[i] < 0 && v[i] > V){
            int s;
            if((V * V - v[i] * v[i]) % (2 * a[i]) == 0) s = (V * V - v[i] * v[i]) / (2 * a[i]) - 1;
            else s = (V * V - v[i] * v[i]) / (2 * a[i]);
            if(s >= 0){
                //cout << d[i] << " " << min(d[i] + s,L) << endl;
                vec.ep(min(d[i] + s,L),d[i]);
            }
        }
    }
    sort(vec.begin(),vec.end());
    rep(i,1,m) p[i] = read();
    p[0] = -1;
    int j = 0,ans1 = 0,ans2 = 0;
    for(int i = 0;i < vec.size();i++){
        //cout << vec[i].lft << " " << vec[i].rgt << endl;
        if(p[j] >= vec[i].lft && p[j] <= vec[i].rgt){
            ans1++;
        }
        else{
            int tmp = j;
            while(j <= m && p[j] <= vec[i].rgt) j++;
            j--;
            //cout << vec[i].rgt << " " << p[j] << endl;
            if(p[j] >= vec[i].lft && p[j] <= vec[i].rgt){
                ans1++;
                ans2++;
            }else j = tmp;
        }
    }
    cout << ans1 << " " << m - ans2 << '\n';
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T = read();
    //T = 1;
    while(T--){
        solve();
    }
    return 0;
}
